<template>
  <div>
    <nav-bar title="固定巡检">
      <template v-slot:right>
        <span @click="fixedStatistcal" v-show="user && user.userType === '01'">统计</span>
      </template>
    </nav-bar>
    <div class="maxinBox">
      <van-dropdown-menu>
        <van-dropdown-item v-model="status" :options="statusList" @change="getTaskAboutMyList" />
        <van-dropdown-item v-model="selectFinish" :options="finishList" @change="getTaskAboutMyList" />
      </van-dropdown-menu>
      <div class="fixedInspection">
        <van-row class="inspectionContent" v-for="(item, index) in inspectionList" :key="index" @click="startInspection(item)">
          <van-col :span="12">
            <span class="fontSize16 fontWeight">{{item.patrolPlanName || item.patrolPointName}}</span><br>
            <span class="fontSize14">{{item.execStartTime | formatDate('YYYY-MM-DD HH:mm')}}</span>
          </van-col>
          <van-col :span="12" style="line-height: 2.5rem;text-align: right;">
            <van-button class="vanButtonActive" round size="small" type="default" v-if="item.completed">已完成</van-button>
            <van-button class="vanButton" round size="small" type="default" v-else>未完成</van-button>
          </van-col>
        </van-row>
      </div>
    </div>
  </div>
</template>

<script>
  import messageAPI from '../../../api/messageAPI.js'
  import fixedInspectionApi from '../../../api/workAPI/fixedInspectionAPI.js'
  import moment from 'moment'
  export default {
    data() {
      return {
        user: {
          userStatus: '',
          userType: '',
        },
        selectFinish: 2,
        status: '',
        statusList: [
          { text: '抄送我的', value: 2 },
        ],
        finishList: [
          { text: '全部', value: 2 },
          { text: '已完成', value: 1 },
          { text: '未完成', value: 0 },
        ],
        inspectionList: []
      }
    },
    methods: {
      //抄送我的/我整改的列表
      getTaskAboutMyList() {
        let finishStatus = JSON.parse(this.selectFinish)
        if (this.selectFinish === 2) {
          finishStatus = ''
        }
        if (this.status === 0) {
          let data = {
            pageNum: 1,
            pageSize: 500,
            completed: finishStatus,
            projectId: localStorage.getItem('projectId')
          }
          fixedInspectionApi.getTaskList(data).then(res => {
            this.inspectionList = res
          })
        } else if(this.status === 1) {
          let data = {
            projectId: localStorage.getItem('projectId'),
            pageNum: 1,
            pageSize: 500,
            completed: finishStatus
          }
          fixedInspectionApi.getAllTask(data).then(res => {
            this.inspectionList = res
          })
        } else {
          let data = {
            pageNum: 1,
            pageSize: 500,
            completed: finishStatus,
            projectId: localStorage.getItem('projectId'),
            dutyType: this.status
          }
          fixedInspectionApi.getTaskAboutMyList(data).then(res => {
            this.inspectionList = res
          })
        }
      },
      fixedStatistcal() {
        this.$router.push({
          path: '/FixedStatistical'
        })
      },
      // 开始巡检页面跳转
      startInspection(data) {
        let fixedDetails = {
          item: data,
          status: this.status
        }
        localStorage.setItem('fixedDetails', JSON.stringify(fixedDetails))
        if (this.status === 2) {
          messageAPI.delInspection(data.trouble.id)
        }
        if (this.status === 0 || this.status === 1) {
          this.$router.push({
            name: 'MyInspection'
          })
        } else {
          this.$router.push({
            name: 'RectificationTask'
          })
        }
      }
    },
    mounted() {
      this.user.userStatus = localStorage.getItem('userStatus')
      this.user.userType = localStorage.getItem('userType')
      if(this.user.userType === '02') {
        this.status = 0
        this.statusList.unshift({
          text: '我的巡检',
          value: 0 ,
        })
      }
      if (this.user && this.user.userType === '01') {
        this.status = 1
        this.statusList.unshift({
          text: '全部巡检',
          value: 1 ,
        })
      }
      this.getTaskAboutMyList()
    }
  }
</script>

<style scoped lang="scss">
  .fixedInspection{
    background-color: #fff;
    .inspectionContent{
      padding: 1.25rem;
      border-bottom: 1px solid #E6E6E6;
     }
  }
</style>
